package de.smarthome.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import de.smarthome.R;

public class ScenarioAdapter extends BaseAdapter {

	private final List<String> objects;
	private final LayoutInflater inflater;

	public ScenarioAdapter(Activity context, List<String> objects) {
		this.objects = objects;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return objects.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View itemView = convertView;
		String item = this.objects.get(position);

		if (itemView == null)
			itemView = this.inflater.inflate(R.layout.item_scenario, null);

		TextView name = (TextView) itemView.findViewById(R.id.itemScenarioName);
		name.setText(item);

		return itemView;
	}
}
